import time
import tkinter as tk

class Window:
    def __init__(self, title='homework', width=800, height=800, staFunc=bool, stoFunc=bool):
        self.w = width
        self.h = height
        self.stat = True
        self.staFunc = staFunc
        self.stoFunc = stoFunc
        self.staIco = None
        self.stoIco = None

        self.root = tk.Tk(className=title)

    def center(self):
        ws = self.root.winfo_screenwidth()
        hs = self.root.winfo_screenheight()
        x = int( (ws/2) - (self.w/2) )
        y = int( (hs/2) - (self.h/2) )
        self.root.geometry('{}x{}+{}+{}'.format(self.w, self.h, x, y))

    def packBtn(self):
        self.btnSer = tk.Button(self.root, command=self.event, width=36, height=15)
        self.btnSer.pack(padx=20, side='left')
        btnQuit = tk.Button(self.root, text='画图', command=self.root.quit, width=30, height=15)
        btnQuit.pack(padx=20, side='right')

    def event(self):
        self.btnSer['state'] = 'disabled'
        if self.stat:
            if self.stoFunc():
                self.btnSer['text'] = '组员:李玉腾，邵嘉欣，刘煜，马行，胡佳琳.'
                self.stat = False
                self.root.iconbitmap(self.stoIco)
            else:
             if self.staFunc():
                self.btnSer['text'] = '软工十二班.'
                self.stat = True
                self.root.iconbitmap(self.staIco)
        self.btnSer['state'] = 'active'

    def loop(self):
        self.root.resizable(False, False)   
        self.packBtn()
        self.center()                       
        self.event()
        self.root.mainloop()

########################################################################
def sta():
    print('画图.')
    return True
def sto():
    print('花.')
    return True

if __name__ == '__main__':
    import sys, os

    w = Window(staFunc=sta, stoFunc=sto)
    w.staIco = os.path.join(sys.exec_prefix, 'DLLs\pyc.ico')
    w.stoIco = os.path.join(sys.exec_prefix, 'DLLs\py.ico')
    w.loop()


    
# -*- coding: cp936 -*-
import turtle
import math

def p_line(t, n, length, angle):
    """Draws n line segments."""
    for i in range(n):
        t.fd(length)
        t.lt(angle)
 
def polygon(t, n, length):
    """Draws a polygon with n sides."""
    angle = 360/n
    p_line(t, n, length, angle)
 
def arc(t, r, angle):
    """Draws an arc with the given radius and angle."""
    arc_length = 2 * math.pi * r * abs(angle) / 360
    n = int(arc_length / 4) + 1
    step_length = arc_length / n
    step_angle = float(angle) / n
 
    # Before starting reduces, making a slight left turn.
    t.lt(step_angle/2)
    p_line(t, n, step_length, step_angle)
    t.rt(step_angle/2)

def petal(t, r, angle):
    """Draws a 花瓣 using two arcs."""
    for i in range(2):
        arc(t, r, angle)
        t.lt(180-angle)

def flower(t, n, r, angle, p):
    """Draws a flower with n petals."""
    for i in range(n):
        petal(t, r, angle)
        t.lt(p/n)

def leaf(t, r, angle, p):
    """Draws a 叶子 and fill it."""
    t.begin_fill() # Begin the fill process.
    t.down()
    flower(t, 1, r, angle, p)
    t.end_fill()

def main():
 
    window= turtle.Screen() #creat a screen
    window.bgcolor("white")
    window.title("draw a flower")
    lucy= turtle.Turtle()
    lucy.shape("turtle")
    lucy.color("red")
    lucy.width(3)
    #lucy.speed(10)
 
# Drawing flower
    flower(lucy, 7, 60, 100, 360)
 
# Drawing pedicel
    lucy.color("brown")
    lucy.rt(90)
    lucy.fd(200)
 
# Drawing leaf 1
    lucy.width(1)
    lucy.rt(270)
    lucy.color("green")
    leaf(lucy, 40, 80, 180)
    lucy.rt(140)
    lucy.color("black")
    lucy.fd(30)
    lucy.lt(180)
    lucy.fd(30)

# Drawing leaf 2
    lucy.rt(120)
    lucy.color("green")
    leaf(lucy, 40, 80, 180)
    lucy.color("black")
    lucy.rt(140)
    lucy.fd(30)
    lucy.ht() # hideturtle
    window.exitonclick()
 
main()


